package clientsController;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ClientsController {
	
	private Lock lock;
	private HashMap<String, ClientThread> clients;
	
	public ClientsController() {
		this.lock = new ReentrantLock();
		this.clients = new HashMap<String, ClientThread>();
	}
	
	public void add(String sensorCode, ObjectOutputStream bufferOut, ObjectInputStream bufferIn) throws IOException {
		ClientThread clientThread = new ClientThread(sensorCode, bufferOut, bufferIn);
		lock.lock();
		this.clients.put(clientThread.getIdentifier(), clientThread);
		lock.unlock();
		clientThread.start();
	}
}
